package com.xiaoshuidi.cloud.module.contract.convert.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

public class GenderConverter implements Converter<Integer> {
        @Override
        public Class supportJavaTypeKey() {
            return Integer.class;
        }

        @Override
        public CellDataTypeEnum supportExcelTypeKey() {
            return CellDataTypeEnum.STRING;
        }

        public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
            if(cellData.getStringValue().equals("男")){
                return 1;
            }else if(cellData.getStringValue().equals("女")){
                return 2;
            }else {
                return 1;
            }
        }

        public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
            WriteCellData<String> cellData = new WriteCellData<String>();
            cellData.setType(CellDataTypeEnum.STRING);
            if(value == 1){
                cellData.setStringValue("男");
            }else if(value == 2){
                cellData.setStringValue("女");
            }else {
                cellData.setStringValue("男");
            }
            return cellData;
        }
    }